
package com.joysuch.wwyt.edu.enums;

public enum QuestionTypes {

    // COURSE("cou", "课程", EduCourse.class, "typeId"),
    SINGLE("S", "单选题"),
    MULTI_CHOICE("M", "多选题"),
    ZG_CHOICE("Z", "主观题"),
    JUDGE("J", "判断题");

    private String code;
    private String name;

    private QuestionTypes(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean is(String code) {
        return this.code.equals(code);
    }

    public static QuestionTypes findByName(String name) {
        QuestionTypes[] values = QuestionTypes.values();
        for (QuestionTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static QuestionTypes findByCode(String code) {
        QuestionTypes[] values = QuestionTypes.values();
        for (QuestionTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        QuestionTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
